package com.linkhub.oms.admin.modules.stock.domain.dto;

import cn.hutool.core.collection.CollUtil;
import com.google.common.collect.Lists;
import com.linkhub.oms.admin.modules.wms.domain.dto.StockCountNoticeDTO;
import com.linkhub.oms.common.util.WmsUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName StockCheckDTO
 * @Description TODO
 * @Author XieYu
 * @Date 2024/7/13 23:34
 * @Version 1.0
 */
@Data
public class StockCheckDTO {
    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "仓库")
    private String stashName;

    @ApiModelProperty(value = "本地商品skuId")
    private String skuId;

    private String businessNo;

    private String type;

    @ApiModelProperty(value = "数量")
    private Integer skuQuantity;


    public static List<StockCheckDTO> convert(StockCountNoticeDTO stockCountNoticeDTO) {
        List<StockCheckDTO> results = Lists.newArrayList();
        if (Objects.nonNull(stockCountNoticeDTO) && Objects.nonNull(stockCountNoticeDTO.getItems())
                && CollUtil.isNotEmpty(stockCountNoticeDTO.getItems().getItem())) {
            for (StockCountNoticeDTO.Item item : stockCountNoticeDTO.getItems().getItem()) {
                StockCheckDTO stockCheckDTO = new StockCheckDTO();
                stockCheckDTO.setUserId(WmsUtil.getUserId(item.getItemCode()));
                stockCheckDTO.setBusinessNo(stockCountNoticeDTO.getCheckOrderCode());
                stockCheckDTO.setStashName(stockCountNoticeDTO.getWarehouseCode());
                stockCheckDTO.setSkuId(WmsUtil.getSkuId(item.getItemCode()));
                stockCheckDTO.setType(item.getInventoryType());
                stockCheckDTO.setSkuQuantity(Integer.parseInt(item.getQuantity()));
                results.add(stockCheckDTO);
            }
        }
        return results;
    }
}
